{include file="public/layout" /}

<body style="background-color: rgb(255, 255, 255); overflow: auto; cursor: default; -moz-user-select: inherit;min-width:400px;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" style="box-shadow:none;min-width: 400px;">
    <div class="flexigrid">
        <div class="header-bar">
            <div class="more">
                <div class="search">
                    <div class="content">
                        <form id="searchForm" action="{:url('OrderVerify/users_select')}" method="get" onsubmit="layer_loading('正在处理');" style="display: unset;">
                            {$searchform.hidden|default=''}
                            <div class="ey-form-item"><label class="users-form-item-label">关键词：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="sDiv2">
                                                <input type="text" size="50" name="keywords" value="{$Request.param.keywords}" class="qsbox" style="width: 170px;" placeholder="用户名">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="ey-form-item" style="margin-left: 20px;">
                                <div class="users-form-item-content">
                                    <span class="bt-xin" onclick="OrderQuery();">查询</span>
                                    <span class="bt-xin-no" onclick="OrderQuery('reset');">重置</span>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <div class="geduan-xin"></div>
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%">
                    <thead>
                    <tr>
                        <th abbr="article_title" axis="col3" class="w50">
                            <div class="tc">ID</div>
                        </th>
                        <th align="left" abbr="article_title" axis="col3" class="">
                            <div style="text-align: left; padding-left: 10px;" class="">用户名</div>
                        </th>
                        <th abbr="choose" axis="col6" class="w50">
                            <div class="tc">操作</div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table style="width: 100%;">
                    <tbody>
                    {empty name="list"}
                        <tr>
                            <td class="no-data" align="center" axis="col0" colspan="50">
                                <div class="no_row">
                                    <div class="no_pic"><img src="__SKIN__/images/null-data.png"></div>
                                </div>
                            </td>
                        </tr>
                    {else/}
                        {foreach name="list" item="vo" key="k" }
                        <tr>
                            <td class="sort">
                                <div class="tc w50">
                                    {$vo.users_id}
                                </div>
                            </td>
                            <td class="" style="width: 100%;">
                                <div class="pl10 text-l10 tl">
                                    <img id="img_head_pic" class="fl" style="width: 40px; height: 40px;" src="{$vo.head_pic|get_head_pic=###}">
                                    <p style="margin-top: 5px;">{$vo.nickname}</p>
                                </div>
                            </td>
                            <td class="operation">
                                <div class="w50 tc">
                                    <a href="javascript:void(0);" onclick="eyou_confirm_choose(this);" data-id="{$vo.users_id}" data-nickname="{$vo.nickname}"
                                       data-litpic="{$vo.head_pic|get_default_pic=###}" class="btn blue">
                                        选择
                                    </a>
                                </div>
                            </td>
                        </tr>
                        {/foreach}
                    {/empty}
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>
        <div class="tDiv">
            <div class="tDiv2">
                {include file="public/page" /}
            </div>
            <div style="clear:both"></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    // 订单查询
    function OrderQuery(isReset) {
        if (isReset && 'reset' == isReset) {
            window.location.href = "{:url('OrderVerify/users_select')}";
        } else {
            $('#searchForm').submit();
        }
    }

    function eyou_confirm_choose(obj){
        var users_id = $(obj).attr('data-id');
        var litpic = $(obj).attr('data-litpic');
        var nickname = $(obj).attr('data-nickname');
        var html = '<img style="float: unset; border: 1px solid #e9edef; width: 24px; height: 24px; border-radius: 50%;" src="'+litpic+'">\n' +
            '                    <a href="javascript:void(0);" data-href="{:url(\'Member/users_edit\',[\'id\'=>'+users_id+'])}" onclick="openFullframe(this, \'会员资料\',\'100%\',\'100%\');" class="mr20">'+nickname+'</a>' +
            '                    <a data-href="{:url(\'OrderVerify/users_select\')}"\n' +
            '                       onclick="openFullframe(this, \'会员选择\',\'60%\',\'80%\');">选择</a>\n' +
            '                    <input type="hidden" name="users_id" id="users_id" value="'+users_id+'">';

        $('#userInfo',window.parent.document).html(html);
        // $('#users_id',window.parent.document).val(users_id);
        parent.layer.closeAll();
    }
    $(document).ready(function(){

        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 点击刷新数据
        $('.fa-refresh').click(function(){
            location.href = location.href;
        });

        $('#searchForm select[name=typeid]').change(function(){
            $('#searchForm').submit();
        });
    });

    /**
     * 获取已选择的数据
     * @returns {Array}
     */
    function getSelectedData() {
        var data = [];
        $('input[name^=ids]').each(function(i,o){
            if($(o).is(':checked')){
                var params = $('#ids_' + $(o).val()).val();
                params = $.parseJSON(params);
                data.push(params);
            }
        })
        if(data.length == 0){
            showErrorAlert('请至少选择一项！');
            return;
        }

        return data;
    }
</script>

<input type="hidden" id="post_stypeid" value="{$stypeidStr}">
<script type="text/javascript">
    $(function() {
        var stypeidStr = $('#post_stypeid').val();
        var stypeidArr = stypeidStr.split(',');
        $('.stypeid').each(function() {
            var _this = $(this);
            var index = $.inArray(String(_this.val()), stypeidArr);
            if (parseInt(index) > -1) {
                _this.attr('checked', true);
                $('#' + _this.data('topid')).attr('checked', true);
                $('#' + _this.data('parent_id')).attr('checked', true);
            }
        });

        $('#goodsStypeid').mouseover(function() {
            $('#ey_fenleitanchuang').show();
        });
        $('#goodsStypeid').mouseout(function() {
            $('#ey_fenleitanchuang').hide();
        });
    });

    function selectStypeid(obj) {
        var isSelect = $(obj).prop('checked');
        var selectID = parseInt($(obj).val());
        var selectLevel = parseInt($(obj).data('level'));
        var selectTopID = parseInt($(obj).data('topid'));
        var selectParentID = parseInt($(obj).data('parent_id'));
        var selectValue1 = selectValue2 = selectValue3 = 0;
        var postStypeidArr = [];
        $('.stypeid').each(function() {
            var _this = $(this);
            if (0 === selectLevel) {
                if (selectID === parseInt(_this.data('topid'))) _this.attr('checked', isSelect);
            } else if (1 === selectLevel) {
                if (selectID === parseInt(_this.data('parent_id'))) _this.attr('checked', isSelect);
            }
            if (1 === selectLevel && 1 === parseInt(_this.data('level')) && selectTopID === parseInt(_this.data('topid'))) {
                if (true === _this.prop('checked')) selectValue1++;
                if (0 === parseInt(selectValue1)) {
                    $('#' + selectTopID).attr('checked', false);
                } else {
                    $('#' + selectTopID).attr('checked', true);
                }
            }
            if (2 === selectLevel && 2 === parseInt(_this.data('level')) && selectParentID === parseInt(_this.data('parent_id'))) {
                if (true === _this.prop('checked')) selectValue2++;
                if (0 === parseInt(selectValue2)) {
                    $('#' + selectParentID).attr('checked', false);
                } else {
                    $('#' + selectTopID).attr('checked', true);
                    $('#' + selectParentID).attr('checked', true);
                }
            }

            // 选中的分类ID加入数组
            if (0 === _this.data('has_children') && true === _this.prop('checked')) postStypeidArr.push(_this.val());
        });

        // 处理二级分类是否选中
        $('.topid_' + selectTopID).each(function() {
            if (true === $(this).prop('checked')) selectValue3++;
        });
        if (0 === parseInt(selectValue3)) $('#' + selectTopID).attr('checked', false);

        // 所有选中的分类数量
        var selectStypeidLength = $('#arctype_table input[name="stypeid[]"]:checked').length;
        if (parseInt(selectStypeidLength) > 0) {
            $('#stypeidCount').attr('placeholder', '已选中 ' + selectStypeidLength + ' 个分类');
        } else {
            $('#stypeidCount').attr('placeholder', '全部');
        }

        // 选中的分类ID数组转字符串
        var postStypeidStr = postStypeidArr.join(',');
        $('#post_stypeid').val(postStypeidStr);
    }
</script>
<script type="text/javascript">
    $(function() {
        setCookies('stypeid-treeClicked-Arr', JSON.stringify({$tree.cookied_treeclicked_arr}) );
    });

    // 点击展开 收缩节点
    function treeClicked(obj, id, reload) {
        if (id == 'all') {
            if (1 == reload) {
                var status = getCookie('stypeid-treeClicked');
                if (!status) status = $(obj).attr('data-status');
            } else {
                var status = $(obj).attr('data-status');
            }
            if (status == 'close') {
                setCookies('stypeid-treeClicked-Arr', JSON.stringify({$tree.parent_ids}));
                setCookies('stypeid-treeClicked_All', 1);//1为全部展开,0-为非全部展开
                $('tr[class^=parent_id_]').show();
                $('.childrenImg').attr('src', '__SKIN__/images/tv-collapsable-last.gif');
                $(obj).attr('data-status', 'open').attr('title','关闭所有子分类').attr('src','__SKIN__/images/tv-collapsable-last.gif');
            } else {
                setCookies('stypeid-treeClicked-Arr', '');
                setCookies('stypeid-treeClicked_All', 0);
                $('tr[data-level=0]').find('img.has_children').attr('src', '__SKIN__/images/tv-collapsable-last.gif').trigger('click');
                $('tr[class^=parent_id_]').removeClass('trSelected');
                $(obj).attr('data-status', 'close').attr('title','展开所有子分类').attr('src','__SKIN__/images/tv-expandable.gif');
            }
            setCookies('stypeid-treeClicked', status);
            return false;
        }

        var src = $(obj).attr('src');
        if (src == '__SKIN__/images/tv-expandable.gif') {
            var arr = [];
            var str = getCookie('stypeid-treeClicked-Arr');
            if ('' == str || null == str || 'null' == str) {
                arr.push(id);
            } else {
                arr = JSON.parse(str);
                if (!arr.includes(id))arr.push(id);
            }
            arr = JSON.stringify(arr);
            setCookies('stypeid-treeClicked-Arr', arr);
            $(".parent_id_"+id).show();
            $(obj).attr('src','__SKIN__/images/tv-collapsable-last.gif');
            var status = 'close';
        } else {
            var key = -1;
            var arr = [];
            var level = '';
            var str = getCookie('stypeid-treeClicked-Arr');
            if ('' != str) {
                arr = JSON.parse(str);
                key = $.inArray(id,arr);
                if (-1 < key) arr.splice(key,1);
                level = $(obj).attr('data-level');
                $(obj).parent().parent().parent().nextAll().each(function() {
                    if ($(this).attr('data-level') > level) {
                        key = $.inArray(parseInt($(this).attr('data-id')), arr);
                        if (-1 < key) arr.splice(key,1);
                    } else {
                        return false;
                    }
                });
                arr = JSON.stringify(arr);
                setCookies('stypeid-treeClicked-Arr', arr);
                setCookies('stypeid-treeClicked_All', 0);
            }

            var status = 'open';
            $(obj).attr('src', '__SKIN__/images/tv-expandable.gif');

            // 如果是点击减号, 遍历循环他下面的所有都关闭
            var fnd = false;
            var cur_tr = obj.parentNode.parentNode.parentNode;
            var tbl = document.getElementById("arctype_table");
            for (var i = 0; i < tbl.rows.length; i++) {
                var row = tbl.rows[i];
                if (row == cur_tr) {
                    fnd = true;
                } else {
                    if (fnd == true) {
                        var cur_level = $(cur_tr).data('level');
                        var level = parseInt($(row).data('level'));
                        if (level > cur_level) {
                            $(row).hide();
                            $(row).find('img.has_children').attr('src','__SKIN__/images/tv-expandable.gif');
                        } else {
                            fnd = false;
                            break;
                        }
                    }
                }
            }
        }
        setCookies('stypeid-treeClicked', status);
    }

</script>
{include file="public/footer" /}